package com.example.joewang.surfaceviewmotion.model;

import com.example.joewang.surfaceviewmotion.R;

/**
 * Created by joewang on 2017/10/19.
 */

public class Snow {

    public static final int resId = R.drawable.snow;

    private int mDirection;   //雪花方向, 0表示左边，1表示右边
    private int mDropSpeed;   //雪花下落速度
    private int mCircleSpeed; //雪花旋转速度
    private int mAngle;       //速度的角度
    private int mXposition;
    private int mYPosition;
    private int mXBonds;     //水平方向上的范围
    private int mYBounds;    //垂直方向上的范围

    public Snow() {

    }

    public Snow(int x, int y) {
        this.mXposition = x;
        this.mYPosition = y;
        this.mDropSpeed = Snow.getRandomSpeed();
        this.mAngle = Snow.getRandomAngle();
    }

    public int getmXposition() {
        return mXposition;
    }

    public void setmXposition(int mXposition) {
        this.mXposition = mXposition;
    }

    public int getmYPosition() {
        return mYPosition;
    }

    public void setmYPosition(int mYPosition) {
        this.mYPosition = mYPosition;
    }

    public int getmDirection() {
        return mDirection;
    }

    public void setmDirection(int mDirection) {
        this.mDirection = mDirection;
    }

    public int getmDropSpeed() {
        return mDropSpeed;
    }

    public void setmDropSpeed(int mDropSpeed) {
        this.mDropSpeed = mDropSpeed;
    }

    public int getmCircleSpeed() {
        return mCircleSpeed;
    }

    public void setmCircleSpeed(int mCircleSpeed) {
        this.mCircleSpeed = mCircleSpeed;
    }

    public int getmAngle() {
        return mAngle;
    }

    public void setmAngle(int mAngle) {
        this.mAngle = mAngle;
    }

    //生成随机的速度
    public static int getRandomSpeed() {
        return (int) (Math.random() * 10) + 5;
    }

    //生成随机的角度
    public static int getRandomAngle() {
        return (int) (Math.random() * 35) + 10;
    }

    public void setBounds(int x, int y) {
        this.mXBonds = x;
        this.mYBounds = y;
    }

    public void updatePosition() {
        if (mDirection == 0) {  //像左边移动
            mXposition = mXposition - (int) (Math.sin(Math.toRadians(mAngle)) * mDropSpeed);
            mYPosition = mYPosition + (int) (Math.cos(Math.toRadians(mAngle)) * mDropSpeed);
        } else {              //像右边移动
            mXposition = mXposition + (int) (Math.sin(Math.toRadians(mAngle)) * mDropSpeed);
            mYPosition = mYPosition + (int) (Math.cos(Math.toRadians(mAngle)) * mDropSpeed);
        }
        if (mXposition < 0) {
            mXposition = mXBonds + mXposition;
        } else if (mXposition > mXBonds) {
            mXposition = mXposition - mXBonds;
        } else if (mYPosition > mYBounds) {
            mYPosition = 0;
        }
    }
}
